﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyEmployees.Models;
using MyEmployees.BLL;

namespace MyEmployees
{
    public partial class FrmAdd : Form
    {
        public FrmAdd()
        {
            InitializeComponent();
        }
              
        EmployeeManage empManage;
        int empId;

        private void FrmAdd_Load(object sender, EventArgs e)
        {
            //获取雇员编号显示出来 
            empManage = new EmployeeManage();
            empId=empManage.GetId();
            lblID.Text = empId.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            txtFN.Text = "";
            txtLN.Text = "";
            txtCountry.Text = "";
            dtpBirthday.Value = DateTime.Now.Date;
            txtLN.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtFN.Text.Trim() == "" || txtLN.Text.Trim() == "" || txtCountry.Text.Trim() == "")
            {
                MessageBox.Show("请把信息填写完整");
                return;
            }

            Employees newemp = new Employees();
            newemp.EmployeeID = empId;
            newemp.FirstName = txtFN.Text;
            newemp.LastName = txtLN.Text;
            newemp.Country = txtCountry.Text;
            newemp.Birthday = dtpBirthday.Value;

            //保存新员工信息
            if (empManage.SaveAdd(newemp))
            {
                MessageBox.Show("添加成功");
                this.Close();
            }
            else
                MessageBox.Show("添加失败");            
        }
    }
}
